﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace cryptcompress
{
    public static class Extensions
    {
        public static void WriteToFileStream(this byte[] data, Stream stream)
        {
            stream.Write(data, 0, data.Length);
        }

        public static void WriteToFileStream(this string data, Stream stream)
        {
            stream.Write(data.ToByteArray(), 0, data.Length);
        }

        public static byte[] ToByteArray(this string str)
        {
            //Zeichenkette in Byte-Array umwandeln
            System.Text.ASCIIEncoding obj = new System.Text.ASCIIEncoding();
            return obj.GetBytes(str);
        }

        public static string ToHash(this string Value)
        {
            //Kennwort in Hashwert umwandeln 
            //Hashwert kann nicht in Kennwort zurückübersetzt werden
            byte[] StrBytes = System.Text.Encoding.UTF8.GetBytes(Value);
            SHA1CryptoServiceProvider hAlgorithm = new SHA1CryptoServiceProvider();
            byte[] hBytes = hAlgorithm.ComputeHash(StrBytes);
            hAlgorithm.Clear();
            string erg = Convert.ToBase64String(hBytes);
            return erg;
        }
    }

}
